// 隐藏手机号
function hideMobile(phone) {
  return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
}

/* 处理支付只能输入两位小数
* add by Jack on 20180525
* @param value
*/
function handlePayAmount(value) {
  let indexOfDot = value.indexOf(".");
  if (indexOfDot == -1) {
    value = value * 1;// 去除前面多余的 0
  } else {
    let str_ = value.substr(indexOfDot + 1);
    //限制只能输入一个小数点  
    if (str_.indexOf(".") != -1) {
      value = value.substr(0, indexOfDot + str_.indexOf(".") + 1);
    }

    if (indexOfDot == 0) {
      value = "0" + value;
    }
    value = value.substr(0, indexOfDot + 3);// 只能输入两位小数

    // TODO 去除前面多余的 0
    if (value > 0 && value.length > (indexOfDot+1)) {
      value = value * 1;
    }
  }
  return value || '';
}


module.exports = {
  hideMobile: hideMobile,
  handlePayAmount: handlePayAmount
}